﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using PowerCreator.LMS.Question.Core;
using PowerCreator.LMS.Question.Entiry;
using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Common.Utils;

public partial class sysadmin_QuestionManager_EditQuestionResource : PowerCreator.LMS.Web.Base.BasePage
{
    //ManagerQuestionResourceInfo objManagerQuestionResourceInfo = new ManagerQuestionResourceInfo();
    //ManagerQuestionInfo questionInfoManager = new ManagerQuestionInfo();
    ManagerQuestion objQuestion = new ManagerQuestion();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewState["UserID"] = 10000;// Session["UserID"].ToString();
            string QuestionResID = Request.QueryString["ID"].ToString();
            ViewState["QuestionResID"] = QuestionResID;
            PageBand();
            InitPage();
        }
    }
    protected override void InitPage()
    {
        base.InitPage();
    }
    private void PageBand()
    {
        VOQuestionResource objQuestionResourceInfo = new VOQuestionResource();
        objQuestionResourceInfo = objQuestion.LoadQuestionResource(int.Parse(ViewState["QuestionResID"].ToString()));
        ViewState["objQuestionResourceInfo"] = objQuestionResourceInfo;

        txtQuestionTypeName.Text = objQuestionResourceInfo.QuestionResFileName;
        txt_Content.Text = objQuestionResourceInfo.QuestionResContent;
        for (int i = 0; i < ddlSystemType.Items.Count; i++)
        {
            if (objQuestionResourceInfo.QuestionResFileType.ToString() == ddlSystemType.Items[i].Value)
            {
                ddlSystemType.Items[i].Selected = true;
                return;
            }
            else
                ddlSystemType.Items[i].Selected = false;
        }

    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        VOQuestionResource objQuestionResourceInfo = (VOQuestionResource)ViewState["objQuestionResourceInfo"];
        HttpPostedFile objPostFile = File1.PostedFile;
        if (objPostFile.FileName == "")
        {
            Script.Alert(this, "msg", "请选择文件");
            return;
        }

        objPostFile.SaveAs(Server.MapPath(WebUtils.WebRoot + "/QeustionResource/" + objQuestionResourceInfo.QuestionResUploadFileName));
        FileInfo objFileInfo = new FileInfo(objPostFile.FileName);

        if (txtQuestionTypeName.Text == "")
        {
            objQuestionResourceInfo.QuestionResFileName = objFileInfo.Name;
        }
        else
        {
            objQuestionResourceInfo.QuestionResFileName = txtQuestionTypeName.Text;
        }

        objQuestionResourceInfo.QuestionResCreateID = int.Parse(ViewState["UserID"].ToString());
        
        objQuestionResourceInfo.QuestionResUpdateTime = DateTime.Now;

        if (objQuestion.UpdateQuestionResource(objQuestionResourceInfo))
        {
            Script.ShowAndRedirect(this, "", "QuestionResourceList.aspx");
        }
        else
        {
            Script.ShowAndRedirect(this, "", "QuestionResourceList.aspx");
        }
        
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Script.RedirectURL("QuestionResourceList.aspx");
    }
}
